package cn.hua.trip.base.domain;

import cn.hua.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Travel extends BaseDomain{

    public static final int STATE_REJECT=0;  //拒绝
    public static final int STATE_NOMAL=1;  //草稿
    public static final int STATE_WAITING=2;  //待审核
    public static final int STATE_RELEASE=3;  //发布

    private String title;  //标题

    @DateTimeFormat(pattern = "yyyy-MM-dd")  //请求参数格式化
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")  //对象转化成json格式时,时间格式化
    private Date travelTime;//旅游时间

    private String perExpends;//人均消费

    private Integer days;//旅游天数

    private Integer person;//和谁旅游

    private User author;//作者

    @DateTimeFormat(pattern = "yyyy-MM-dd")  //请求参数格式化
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")  //对象转化成json格式时,时间格式化
    private Date createTime;//创建时间

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;//发布时间

    private Boolean isPublic =true;//是否公开   默认公开

    private Region place;//旅游地区

    private String coverUrl;//封面

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date lastUpdateTime;//最后更新时间

    private Integer state=STATE_NOMAL;//状态

    //关联内容对象
    private TravelContent travelContent;

    public String getStateName(){
        String temp = "";
        if(state!=null){
            if (state ==STATE_REJECT){
                return "拒绝";
            }else if (state ==STATE_NOMAL){
                return "草稿";
            }else if (state==STATE_WAITING){
                return "待审核";
            }else if (state ==STATE_RELEASE){
                return "发布";
            }
        }
        return temp;
    }

    public String getJsonString(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("state",state);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }
}